package com.yhh.college_information_platform.config;

import com.yhh.college_information_platform.interceptor.AuthInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * Web MVC 配置
 *
 * @author yhh
 * @date 2025-10-05
 * @update 2025-10-30 改用注解式权限控制
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    private AuthInterceptor authInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authInterceptor)
                // 拦截所有API请求
                .addPathPatterns("/**")
                // 仅排除静态资源和系统路径
                .excludePathPatterns(
                        "/druid/**",
                        "/error",
                        "/swagger-ui/**",
                        "/v3/api-docs/**",
                        "/webjars/**",
                        "/favicon.ico"
                );
        // 注意：所有业务接口的权限控制现在通过 @PublicAccess、@RequireAuth、@RequireRole 注解实现
    }
}
